#pragma once

#include "base/core/singleton.h"
#include "base/core/point3.h"
#include "MonsterRefCfg.h"


#include <unordered_map>
#include <set>
#include "Common/CharacterDefine.h"

class SceneGenenalCreatureRef
{
	typedef std::unordered_map<CharIDType, MonsterRefLocation> mapMonsterIdToRefLocation;
	typedef std::unordered_map<CharIDType, NPCRefLocation> mapNpcIdToRefLocation;
public:
	SceneGenenalCreatureRef(uint32_t sceneId);
	~SceneGenenalCreatureRef();
public:
	bool Init();
	bool UnInit();

	bool InitMonsterRef(uint32_t mapId, uint32_t sceneId);
	bool UnInitMonsterRef();

	bool InitNpcRef(uint32_t mapId, uint32_t sceneId);
	bool UnInitNpcRef();

	bool InitCollectRef(uint32_t mapId,uint32_t sceneId);
	bool UnInitCollectRef();
public:
	void monsterDead(CharIDType monsterCid);
	void npcDead(CharIDType npcCid);
public:
	void Update(uint32_t sceneId, uint64_t tick);
	void UpdateNpcTeam(uint32_t sceneId, uint64_t tick, uint32_t npcTeamId);
protected:
	uint32_t m_sceneId = 0;
	mapMonsterIdToRefLocation m_curMonsterCids;
	mapMonsterIdToRefLocation m_deadMonsterCids;
	mapNpcIdToRefLocation m_curNpcCids;
	mapNpcIdToRefLocation m_deadNpcCids;
	std::unordered_map<uint32_t, mapNpcIdToRefLocation> m_deadNpcTeamCids;
};

class GeneralCreatureRefMgr : public ManualSingleton<GeneralCreatureRefMgr>
{
	friend class ManualSingleton< GeneralCreatureRefMgr>;
	typedef std::unordered_map<uint32_t, SceneGenenalCreatureRef*> sceneRefCreatureMap;
public:
	GeneralCreatureRefMgr();
	~GeneralCreatureRefMgr();
public:
	bool Init();
	bool UnInit();
	bool InitSceneRef(uint32_t mapId, uint32_t sceneId);
	bool UnInitSceneRef(uint32_t sceneId);
public:
	void UpdateNpcTeamDead(uint32_t sceneId, uint64_t tick, uint32_t npcTeamId);
	void monsterDead(uint32_t sceneId, CharIDType monsterCid);
	void npcDead(uint32_t sceneId, CharIDType npcCid);
public:
	virtual bool Update(uint64_t tick);
private:
	sceneRefCreatureMap m_curScene;
};

#define g_MakeGeneralCreatureRefMgr() (GeneralCreatureRefMgr::Instance())
#define g_GetGeneralCreatureRefMgr() (GeneralCreatureRefMgr::GetInstance())
#define g_DelGeneralCreatureRefMgr() (GeneralCreatureRefMgr::Destroy())
